﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EmaMetadata;
using System.IO;

namespace MetadataTest
{
    [TestClass]
    public class UnitTest3
    {
        [TestMethod]
        public void FitweesUT()
        {
            EmaBatch b = Factory.LoadBatchFromString(Resource1.planetside2);

            // File should have one product
            Assert.AreEqual(b.Products.Count, 1);

            // Okay, let's examine this product
            EmaProduct p = b.Products[0];

            // Verify that its identities loaded correctly
            Assert.AreEqual(p.GetIdentity("org.gs1", "GTIN-14").Value, "00014633098891");
            Assert.AreEqual(p.GetIdentity("com.eedar", "EEDAR").Value, "219511");
            Assert.AreEqual(p.GetIdentity("com.microsoft", "GUID").Value, "{0002E101-0000-0000-C000-000000000046}");

            // Verify that all the titles are correct
            Assert.AreEqual(p.GetTitle("org.entmerch", "Complete").Value, "Planetside 2"); //GetIdentity returns an EmaTitle, and Value is a string variable of that EmaTitle
            Assert.AreEqual(p.GetTitle("org.entmerch", "Medium").Value, "Planetside 2");
            Assert.AreEqual(p.GetTitle("org.entmerch", "Brief").Value, "Planetside 2");
            Assert.AreEqual(p.GetTitle("org.entmerch", "Sorting").Value, "Planetside 2");

            // Verify descriptions
            Assert.AreEqual(p.GetDescription("org.entmerch", "short").Value, "PlanetSide 2 is a free-to-play Massively Multiplayer Online FPS that delivers truly epic, massive combat!");
            Assert.AreEqual(p.GetDescription("org.entmerch", "long").Value, "Planetside 2 (formerly known as PlanetSide Next) is a Massively Multiplayer Online First Person Shooter (MMOFPS) game from Sony Online Entertainment (SOE) and is the sequel to their earlier game PlanetSide. Planetside 2 was released November 20, 2012. ");

            // TODO: Correct this test
            //Assert.AreEqual(p.GetDesc("org.entmerch", "requirements").Value, "Windows 7, Intel i5 processor or higher / AMD Phenom II X6 or higher, 8 GB RAM, 15 GB free, 1,024 MB RAM, nVidia GeForce GTX 500 series or higher / AMD HD 6870 or higher DirectX ");

            // Verify a couple hand selected facts
            Assert.AreEqual(p.EditionType.FactName, "Platinum");
            Assert.AreEqual(p.MaxPlayers, 2000);
            Assert.AreEqual(p.Platform.FactName, "PC");

            // TODO: Correct this test
            // Verify a couple hand selected facts
            //Assert.AreEqual(p.PrimaryDeveloper, "Primary Developer");
        }

        public void SaveAndLoadTest()
        {
            // Read in the test file from ted's sample data folder
            EmaBatch b = Factory.LoadBatch("..\\..\\..\\..\\SampleXML\\schema_template.xml");

            // Save this record to a string
            string xml = Factory.SaveBatchToString(b);

            // Reload the string back into a batch
            EmaBatch reloaded = Factory.LoadBatchFromString(xml);
        }

        public void CompareSerializedObjects()
        {
            // Read in a batch and convert one product to string
            EmaBatch b = Factory.LoadBatch("..\\..\\..\\..\\SampleXML\\schema_template.xml");
            string xml = Factory.ProductToString(b.Products[0]);

            // Convert this XML back to a product, then back to XML
            EmaProduct p = Factory.StringToProduct(xml);
            string xml_2 = Factory.ProductToString(p);

            // This XML should match exactly the XML we had previously
            Assert.AreEqual(xml, xml_2);
        }
    }
}

